<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="Hello Pro"></u-loading-page>
		<view v-if="!loadding" class="main">
			<view class="team_info">
				<view class="avatar">
					<image :src="teamData.avatar"></image>
				</view>
				<view class="content">
					<view class="name">
						{{teamData.nickname}}
					</view>
					<view class="mobile">
						{{teamData.mobile}}
					</view>
				</view>
			</view>
			<view class="setting">
				<view class="title">
					提现设置
				</view>
				<view class="lists">
					<view class="items">
						<view class="labels">
							提现
						</view>
						<view class="values">
							<u-switch v-model="withdraw" @change="withdrawChange"></u-switch>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadding: true,
				id: null,
				teamData: {},
				userinfo: {},
				withdraw: false
			}
		},
		onLoad(e) {
			this.id = e.id
			this.userinfo = uni.getStorageSync('userinfo')
			this.loadData()
		},
		methods: {
			// 加载数据
			async loadData() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Team/getTeamDetail',
					data: {
						id: this.id
					},
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					this.loadding = false
					this.teamData = res.data
					if (res.data.withdraw_state == 1) {
						this.withdraw = true
					} else {
						this.withdraw = false
					}
				}
			},
			// 切换提现状态
			withdrawChange(e) {
				var msg = ""
				if (e) {
					msg = "确定要开启提现状态吗？"
				} else {
					msg = "确定要关闭提现状态吗，关闭后其所有团队将一同关闭？"
				}
				var that = this
				uni.showModal({
					title: '提示',
					content: msg,
					success: function(res) {
						if (res.confirm) {
							that.setTeamWithdrawState()
						} else {
							if (e) {
								that.withdraw = false
							} else {
								that.withdraw = true
							}
						}
					}
				});
			},
			// 修改提现状态
			async setTeamWithdrawState() {
				var withdraw_state = 1
				if (this.withdraw) {
					withdraw_state = 1
				} else {
					withdraw_state = 2
				}
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Team/setTeamWithdrawState',
					data: {
						id: this.id,
						withdraw_state: withdraw_state
					},
					header: {
						'token': this.userinfo.token
					}
				});
				uni.hideLoading()
				uni.showToast({
					title: res.msg,
					icon: "none"
				});
				if (res.code == 1) {
					
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}
	.main {
		padding: 20rpx;
		
		.team_info {
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			height: 120rpx;
			
			.avatar {
				float: left;
				
				image {
					border-radius: 20rpx;
					width: 120rpx;
					height: 120rpx;
				}
			}
			
			.content {
				float: left;
				margin-left: 20rpx;
				font-size: 34rpx;
				
				.name {
					font-weight: bold;
					line-height: 60rpx;
				}
				
				.mobile {
					font-size: 30rpx;
					line-height: 60rpx;
					color: #c8c9cc;
				}
			}
		}
		
		.setting {
			margin-top: 20rpx;
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			
			.title {
				padding: 0 0 20rpx 0;
				font-size: 34rpx;
				font-weight: bold;
				border-bottom: 1px dashed #f4f4f5;
			}
			
			.lists {
				padding: 20rpx 0;
				
				.items {
					display: flex;
					justify-content: space-between;
				}
			}
		}
	}
</style>
